<<<<<<< HEAD
"""
最小二乘法拟合一个形如y=a+bx^2的经验公式
"""

import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit

plt.style.use(['grid', 'muted'])

x0 = np.array([19, 25, 31, 38, 44])
y0 = np.array([19.0, 32.3, 49.0, 73.3, 97.8])
def fun(x, a, b): return a + b * x**2


popt, _ = curve_fit(fun, x0, y0)
a, b = popt
y1 = fun(x0, a, b)

plt.figure(figsize=(8, 6))
plt.plot(x0, y0, '*', label='original values')
plt.plot(x0, y1, 'r', label='curve_fit values')

plt.xlabel('x axis')
plt.ylabel('y axis')
plt.legend(loc="lower right")
plt.title('Curve Fitting (y={:.3f}x+{:.3f}x^2)'.format(a, b))
plt.show()
=======
"""
最小二乘法拟合一个形如y=a+bx^2的经验公式
"""

import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit

plt.style.use(['grid', 'muted'])

x0 = np.array([19, 25, 31, 38, 44])
y0 = np.array([19.0, 32.3, 49.0, 73.3, 97.8])
def fun(x, a, b): return a + b * x**2


popt, _ = curve_fit(fun, x0, y0)
a, b = popt
y1 = fun(x0, a, b)

plt.figure(figsize=(8, 6))
plt.plot(x0, y0, '*', label='original values')
plt.plot(x0, y1, 'r', label='curve_fit values')

plt.xlabel('x axis')
plt.ylabel('y axis')
plt.legend(loc="lower right")
plt.title('Curve Fitting (y={:.3f}x+{:.3f}x^2)'.format(a, b))
plt.show()
>>>>>>> a66c8eec2c3bbe955d7da215f43ffffda9c7b6b5
